package seo;

import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

import util.TimeOut;

public class Tags_De_La_Page {
	private Document doc;
	private int nbr_A_HREF;
	private int nbr_Mots_page;
	
	public Tags_De_La_Page() {
		super();
	}

	public Tags_De_La_Page(Document doc) {
		super();
		this.doc = doc;
	}

	public Document getDoc() {
		return doc;
	}

	public void setDoc(Document doc) {
		this.doc = doc;
	}

	private int nbrBaliseH1(){
		return doc.select("h1").size();
	}
	
	private int nbrBaliseH2(){
		return doc.select("h2").size();
	}
	
	private int nbrBaliseH3(){
		return doc.select("h3").size();
	}
	
	private int nbrBalise_B_STRONG(){
		return doc.select("b").size()+doc.select("strong").size();
	}
	
	private int nbrBalise_I_EM(){
		return doc.select("i").size()+doc.select("em").size();
	}
	
	private int nbrBaliseIMG(){
		return doc.select("img").size();
	}
	
	private int nbrBaliseTABLE(){
		return doc.select("table").size();
	}
	
	private int nbrBaliseDIV(){
		return doc.select("div").size();
	}
	
	private int nbr_A_HREF_Interne(){
		int counter = 0;
		for(Element str:  doc.select("a")){
			if(str.attr("href").startsWith("/") || str.attr("href").startsWith(doc.baseUri()))
				counter++;
		}
		return counter;
	}
	
	private int nbr_A_HREF_Externe(){
		int counter = 0;
		String[] params = doc.baseUri().split("\\.");
		for(Element str:  doc.select("a")){
			// les hrefs qui contients ."nomdusite".   			ou qu'ils commencent par / 			 ou vide #
			if(!str.attr("href").contains("."+params[1]+".") && !str.attr("href").startsWith("/") && !str.attr("href").startsWith("#"))
				counter++;
		}
		return counter;
	}
	
	private int nbr_Mots_page(){
		return doc.select("div").size();
	}
}
